//
//  BKChannelModel.m
//  网易新闻
//
//  Created by mac on 16/7/19.
//  Copyright © 2016年 xbk. All rights reserved.
//

#import "BKChannelModel.h"

@implementation BKChannelModel

+ (instancetype) labelWithDict:(NSDictionary *)dict{

    BKChannelModel *model = [[BKChannelModel alloc]init];
    
    [model setValuesForKeysWithDictionary:dict];
    
    return model;
}

- (void)setValue:(id)value forUndefinedKey:(NSString *)key{

}

+ (NSArray *)channels{

    //1.获取路径
    NSString *path = [[NSBundle mainBundle]pathForResource:@"topic_news.json" ofType:nil];
    
    //2.根据路径创建数组
    
    //2.1 json是一个二进制数据
    NSData *jsonData = [NSData dataWithContentsOfFile:path];
    
    //2.2 反序列化转成字典
    NSDictionary *jsonDic = [NSJSONSerialization JSONObjectWithData:jsonData options:0 error:nil];
    
    //2.3 根据json中的key值取出value,创建字典
    NSArray *jsonArr = jsonDic[@"tList"];
    
    //3.遍历数组进行字典转模型
    
    //3.1 创建可变数组
    NSMutableArray *arrM = [NSMutableArray array];
    
    for (NSDictionary *dic in jsonArr) {
        
        BKChannelModel *model = [BKChannelModel labelWithDict:dic];
        
        [arrM addObject:model];
    }
    
    //对标签按照tid进行排序
    [arrM sortUsingComparator:^NSComparisonResult(BKChannelModel *obj1, BKChannelModel *obj2) {
        
        return [obj1.tid compare:obj2.tid];
    }];
    
    return arrM.copy;
    
}

- (NSString *)description{

    return [NSString stringWithFormat:@"%@ %@",self.tid,self.tname];
}

@end





